package com.qishon.pc.domain.Controller;

import com.qishon.pc.domain.Application.ProgressControlManager;
import com.qishon.pc.domain.model.ProgressControl;
import com.qishon.pc.domain.service.ProgressControlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created by xm on 2016/12/23.
 */
@Controller
public class ProgressControlController {
    @Autowired
    ProgressControlManager progressControlManager;

    @Autowired
    ProgressControlService progressControlService;

    @GetMapping("/progressControl")
    public String welcome(Map<String,Object> map,  Model model) {
        model.addAttribute("progressControls", progressControlManager.findByGirard(map));
        return "progressControl";
    }


    @GetMapping("/progressUIJson")
    @ResponseBody
    public List<ProgressControl> showDashboardJson(Map<String,Object> map, Model model) {
        return progressControlManager.findUnComplete(map);
    }

    @GetMapping("/progressUI")
    public String showDashboard(Map<String,Object> map,  Model model) {
        //model.addAttribute("progressControls", progressControlManager.findUnComplete(map));
        System.out.println("map:"+map);
        return "progressUI";
    }

    @GetMapping("/completeUIJson")
    @ResponseBody
    public List<ProgressControl> showCompleteUIJson(Map<String,Object> map, Model model) {
        return progressControlManager.findComplete(map);
    }

    @RequestMapping("/completeJson")
    @ResponseBody
    public String updateCompleteJson(@RequestParam(value = "id", required = false) String id){
        ProgressControl progressControl = progressControlService.findById(Integer.parseInt(id));
        progressControlService.updateProStatus(progressControl,1);
        return "success";
    }
}
